package fr.charlott.view;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.event.DashboardReorderEvent;
import org.primefaces.model.DashboardColumn;
import org.primefaces.model.DashboardModel;
import org.primefaces.model.DefaultDashboardColumn;
import org.primefaces.model.DefaultDashboardModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import fr.charlott.business.service.PersonneService;

@Component("adminDashboardControler")
@Scope("view")
public class AdminDashboardControler extends CharlottControler {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * DashboardModel
	 */
	private DashboardModel model;
	
	private DashboardModel categoryModel;
	
	public AdminDashboardControler() {
		super();
	}

	@Autowired(required = true)
	public AdminDashboardControler(PersonneService PersonneService) {
		this();
		
		model = new DefaultDashboardModel();  
        DashboardColumn column1 = new DefaultDashboardColumn();  
          
        column1.addWidget("nouvelleSaison");
        column1.addWidget("listeSaisons");
  
        model.addColumn(column1);  
        
        categoryModel = new DefaultDashboardModel();  
        DashboardColumn categoryColumn1 = new DefaultDashboardColumn();  
          
        categoryColumn1.addWidget("nouvelleCategorie");
        categoryColumn1.addWidget("listeCategories");
  
        categoryModel.addColumn(categoryColumn1);  
	}
	
	public void handleReorder(DashboardReorderEvent event) {  
	    FacesMessage message = new FacesMessage();  
	    message.setSeverity(FacesMessage.SEVERITY_INFO);  
	    message.setSummary("Reordered: " + event.getWidgetId());  
	    message.setDetail("Item index: " + event.getItemIndex() + ", Column index: " + event.getColumnIndex() + ", Sender index: " + event.getSenderColumnIndex());  
	      
	    addMessage(message);  
	}  
	  
	  
	private void addMessage(FacesMessage message) {  
	    FacesContext.getCurrentInstance().addMessage(null, message);  
	}  
	  
	public DashboardModel getModel() {  
	    return model;  
	}

	public DashboardModel getCategoryModel() {
		return categoryModel;
	}
}
